package org.iabako.shared.querydefinition.columndefinition;

import org.iabako.client.tools.Messages;
import org.iabako.shared.querydefinition.dto.QueryResultValueType;

import java.io.Serializable;

/**
 * Created by jose on 03/09/14.
 */
public enum SaleColumnEnum implements ColumnDefinition, Serializable {

    saleNumberForQuote("sale.number", null, "result_table_sale_number", "columnSminus columnleftalign smalltable", QueryResultValueType.STRING, 3000, false),
    productsServices("sale.productsServicesAsString", null, "result_table_sale_product_service", "columnM smalltable", QueryResultValueType.STRING, 6000, false),
    client("client.name", null, "result_table_sale_client", "columnMplus smalltable", QueryResultValueType.STRING, 6000, false),
    date("sale.date", null, "result_table_sale_date", "columnS", QueryResultValueType.DATE, 3000, false),
    quoteDate("sale.date", null, "result_table_sale_quote", "columnS", QueryResultValueType.DATE, 3000, false),
    dateLastModification("sale.lastModificationDate", null, null, null, null, 0, false),
    price("sale.recalculatedTotal", null, "result_table_sale_price", "columnS columnrightalign", QueryResultValueType.DOUBLE, 4000, false),
    payed("(select sum(payment.amount) from Sale sale1 " +
            "left outer join sale1.payments payment where sale1 = sale group by sale.id) as sum_payed", null,
            "result_table_sale_payed", "columnS columnrightalign", QueryResultValueType.DOUBLE, 4000, false),
    receivable("(select sum(installment.amount) from Sale sale2 " +
            "left outer join sale2.installments installment where sale2 = sale group by sale.id) as sum_receivable", null,
            "result_table_sale_receivable", "columnS columnrightalign", QueryResultValueType.DOUBLE, 4000, false),
    status("sale.status", null, "result_table_sale_status", "columnS columncenteralign", QueryResultValueType.ENUM, 4000, false),

    //to filter
    productId("products.product.id", "join sale.productsServices products", null, null, null, 0, false),
    serviceId("services.service.id", "join sale.productsServices services", null, null, null, 0, false),
    clientId("sale.client.id", "left outer join sale.client client", null, null, null, 0, false),
    salePaymentsDate("payment.date", "join sale.payments payment", null, null, null, 0, false),
    saleInstallmentsDate("installment.date", "join sale.installments installment", null, null, null, 0, false),
    saleInstallmentsPaymentRequestBeforeDate("installment.requestBeforeDate", "join sale.installments installment", null, null, null, 0, false),
    saleInstallmentsPaymentRequestAfterDate("installment.requestAfterDate", "join sale.installments installment", null, null, null, 0, false),

    //default filter with user session
    saleEnterprise("sale.enterprise", null, null, null, null, 0, false),
    saleQuote("sale.quote", null, null, null, null, 0, false),
    //To filter in tracking
    saleId("sale.id", null, null, null, null, 0, false),

    //to show in excel export
    saleNumber("sale.number", null, "result_table_sale_number", null, QueryResultValueType.STRING, 3000, true),
    clientNumber("client.number", null, "result_table_sale_client_number", null, QueryResultValueType.STRING, 3000, true);

    private String hqlDefinition;
    private String hqlJoin;
    private String labelKey;
    private String className;
    private QueryResultValueType queryResultValueType;
    private int excelColumnWidth;
    private boolean onlyInExcelExport;

    SaleColumnEnum(String hqlDefinition, String hqlJoin, String labelKey, String className, QueryResultValueType queryResultValueType, int excelColumnWidth, boolean OnlyInExcelExport) {
        this.hqlDefinition = hqlDefinition;
        this.hqlJoin = hqlJoin;
        this.labelKey = labelKey;
        this.className = className;
        this.queryResultValueType = queryResultValueType;
        this.excelColumnWidth = excelColumnWidth;
        this.onlyInExcelExport = OnlyInExcelExport;
    }

    public String getHqlDefinition() {
        return hqlDefinition;
    }

    public String getHqlJoin() {
        return hqlJoin;
    }

    public String getLabel() {
        return Messages.getLabel(labelKey);
    }

    public String getLabelKey() {
        return labelKey;
    }

    public QueryResultValueType getQueryResultValueType() {
        return queryResultValueType;
    }

    public String getClassName() {
        return className;
    }

    public String getIconClassName() {
        return null;
    }

    public boolean isOnlyInExcelExport() {
        return onlyInExcelExport;
    }

    public int getExcelColumnWidth() {
        return excelColumnWidth;
    }

    public String getIconClassNameEmpty() {
        return null;
    }

    public String getTextEmpty() {
        return null;
    }
}
